package com.alasbusy.alasbusyapp.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.alasbusy.alasbusyapp.R;
import com.alasbusy.alasbusyapp.base.BaseActivity;
import com.alasbusy.alasbusyapp.utils.RegexUtils;
import com.zhy.android.percent.support.PercentLinearLayout;

public class RegisActivity extends BaseActivity implements View.OnClickListener {

    private EditText regis_name;
    private TextView regis_name_tishi;
    private EditText regis_password;
    private TextView regis_pwd_tishi;
    private EditText password_again;
    private TextView regis_pwdagain_tishi;
    private PercentLinearLayout regis_btn;

    @Override
    protected void initView() {
        PercentLinearLayout login_title = findViewById(R.id.regis_title);
        setTop(login_title);
        getVisibility(true, this);
        getTitle("注册");

        regis_name = findViewById(R.id.regis_name);
        regis_name_tishi = findViewById(R.id.regis_name_tishi);
        regis_password = findViewById(R.id.regis_password);
        regis_pwd_tishi = findViewById(R.id.regis_pwd_tishi);
        password_again = findViewById(R.id.password_again);
        regis_pwdagain_tishi = findViewById(R.id.regis_pwdagain_tishi);
        regis_btn = findViewById(R.id.regis_btn);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        regis_btn.setOnClickListener(this);
    }

    @Override
    public int getLayout() {
        return R.layout.activity_regis;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.regis_btn:
                String name = regis_name.getText().toString();
                String pwd = regis_password.getText().toString();
                String pwd_again = password_again.getText().toString();
                if (!TextUtils.isEmpty(name)) {
                    regis_name_tishi.setVisibility(View.INVISIBLE);
                    if(RegexUtils.isChinaPhoneLegal(name)) {
                        if (!TextUtils.isEmpty(pwd)) {
                            regis_pwd_tishi.setVisibility(View.INVISIBLE);
                            if(RegexUtils.isPwdLegal(pwd)) {
                                if (pwd.equals(pwd_again)) {
                                    regis_pwdagain_tishi.setVisibility(View.INVISIBLE);

                                } else {
                                    regis_pwdagain_tishi.setVisibility(View.VISIBLE);
                                    regis_pwdagain_tishi.setText("两次密码不一致");
                                }
                            }else {
                                regis_pwd_tishi.setVisibility(View.VISIBLE);
                                regis_pwd_tishi.setText("密码由6-14位数字和字母组成.");
                            }
                        } else {
                            regis_pwd_tishi.setVisibility(View.VISIBLE);
                            regis_pwd_tishi.setText("帐号不能为空.");
                        }
                    }else {
                        regis_name_tishi.setVisibility(View.VISIBLE);
                        regis_name_tishi.setText("帐号格式不正确.");
                    }
                } else {
                    regis_name_tishi.setVisibility(View.VISIBLE);
                    regis_name_tishi.setText("帐号不能为空.");
                }
                break;
        }
    }
}
